Telegram Group & Telegram Channel
Напишите логистическую регрессию

import numpy as np

class LogisticRegression:

def __init__(self, learning_rate=0.01, n_iters=1000):
self.learning_rate = learning_rate
self.n_iters = n_iters
self.weights = None
self.bias = None

def fit(self, X, y):
# initialize weights and bias to zeros
n_samples, n_features = X.shape
self.weights = np.zeros(n_features)
self.bias = 0

# gradient descent optimization
for i in range(self.n_iters):
# calculate predicted probabilities and cost
z = np.dot(X, self.weights) + self.bias
y_pred = self._sigmoid(z)
cost = (-1 / n_samples) * np.sum(y * np.log(y_pred) + (1 - y) * np.log(1 - y_pred))

# calculate gradients
dw = (1 / n_samples) * np.dot(X.T, (y_pred - y))
db = (1 / n_samples) * np.sum(y_pred - y)

# update weights and bias
self.weights -= self.learning_rate * dw
self.bias -= self.learning_rate * db

def predict(self, X):
# calculate predicted probabilities
z = np.dot(X, self.weights) + self.bias
y_pred = self._sigmoid(z)
# convert probabilities to binary predictions
return np.round(y_pred).astype(int)

def _sigmoid(self, z):
return 1 / (1 + np.exp(-z))


#python
#машинное_обучение



tg-me.com/ds_interview_lib/611
Create:
Last Update:

Напишите логистическую регрессию

import numpy as np

class LogisticRegression:

def __init__(self, learning_rate=0.01, n_iters=1000):
self.learning_rate = learning_rate
self.n_iters = n_iters
self.weights = None
self.bias = None

def fit(self, X, y):
# initialize weights and bias to zeros
n_samples, n_features = X.shape
self.weights = np.zeros(n_features)
self.bias = 0

# gradient descent optimization
for i in range(self.n_iters):
# calculate predicted probabilities and cost
z = np.dot(X, self.weights) + self.bias
y_pred = self._sigmoid(z)
cost = (-1 / n_samples) * np.sum(y * np.log(y_pred) + (1 - y) * np.log(1 - y_pred))

# calculate gradients
dw = (1 / n_samples) * np.dot(X.T, (y_pred - y))
db = (1 / n_samples) * np.sum(y_pred - y)

# update weights and bias
self.weights -= self.learning_rate * dw
self.bias -= self.learning_rate * db

def predict(self, X):
# calculate predicted probabilities
z = np.dot(X, self.weights) + self.bias
y_pred = self._sigmoid(z)
# convert probabilities to binary predictions
return np.round(y_pred).astype(int)

def _sigmoid(self, z):
return 1 / (1 + np.exp(-z))


#python
#машинное_обучение

BY Библиотека собеса по Data Science | вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/ds_interview_lib/611

View MORE
Open in Telegram


Библиотека собеса по Data Science | вопросы с собеседований Telegram | DID YOU KNOW?

Date: |

Telegram announces Search Filters

With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.

The STAR Market, as is implied by the name, is heavily geared toward smaller innovative tech companies, in particular those engaged in strategically important fields, such as biopharmaceuticals, 5G technology, semiconductors, and new energy. The STAR Market currently has 340 listed securities. The STAR Market is seen as important for China’s high-tech and emerging industries, providing a space for smaller companies to raise capital in China. This is especially significant for technology companies that may be viewed with suspicion on overseas stock exchanges.

Библиотека собеса по Data Science | вопросы с собеседований from kr


Telegram Библиотека собеса по Data Science | вопросы с собеседований
FROM USA